import Api from './api'
import Address from './address'

/**
 *
 * @param page
 * @returns {Promise<{data: *, result: *}>}
 */
const searchList = async (keyword) => {
  let url = Address.searchList(keyword)
  let res = await Api.netFetch(url)
  if (res && res.result) {
    let data = res.data
    data.content.forEach((item) => {
      let ex = {
        title: item.contents.title,
        image: item.thumbnail_path,
        tag: item.contents.tags[0],
        view_count: item.contents.view_count,
      }
      item.ex = ex
    })
    data.product.forEach((item) => {
      let ex = {
        id: item.id,
        name: item.name,
        price: item.price,
        image: item.image,
        count: item.user_count,
      }
      item.ex = ex
    })
    data.course.forEach((item) => {
      let ex = {
        name: item.name,
        image: item.image_path,
        ratio: item.ratio,
      }
      item.ex = ex
    })
    data.evaluation.forEach((item) => {
      let ex = {
        id: item.id,
        name: item.name,
        image: item.image_path,
        desc: item.min_desc,
        count: item.view_count,
        is: item.isUserEvaluation,
      }
      item.ex = ex
    })
    return {
      data: data,
      result: res.result,
    }
  }
}

export default {
  searchList,
}
